package com.example.ymm.modules1.controller.user;

import com.example.ymm.model.CommonResult;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.controller.BaseController;
import com.example.ymm.modules1.entity.my.user.DbComment;
import com.example.ymm.modules1.entity.my.user.DbOrderItem;
import com.example.ymm.modules1.query.DbCommentQueryCriteria;
import com.example.ymm.modules1.service.user.DbCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/hl/user/comment")
@Api(tags = "用户端 用户评论接口")
@Slf4j
@CrossOrigin
public class UserCommentController extends BaseController {

    @Autowired
    DbCommentService dbCommentService;

    @ApiOperation(value = "评论列表")
    @RequestMapping(value = "/commentList", method = RequestMethod.POST)
    public CommonResult commentList(@Valid DbCommentQueryCriteria criteria, YmPageDto ymPage) {
        try{
            TableList<DbComment> list = dbCommentService.list(criteria, ymPage);
            return CommonResult.success(list,"获取成功");
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return CommonResult.error(e.getMessage());
        }
    }


    @ApiOperation(value = "发表评论")
    @RequestMapping(value = "/addComment", method = RequestMethod.POST)
    public CommonResult addComment(@Valid DbComment comment) {
        try{
            dbCommentService.saveOrUpdate(comment);
            return CommonResult.success();
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return CommonResult.error(e.getMessage());
        }
    }


}
